package njit.mykafka;

import java.util.Properties;
import java.util.Collections;
import org.apache.kafka.clients.consumer.*;

public class SimpleCounsumer {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put("bootstrap.servers", "localhost:9092");
        props.put("group.id", "my-replicated-topic");
        props.put("enable.auto.commit", "true");
        props.put("auto.commit.interval.ms", "1000");
        props.put("session.timeout.ms", "30000");
        props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer");
        KafkaConsumer<String, String> consumer = new KafkaConsumer<String, String>(props);
        consumer.subscribe(Collections.singletonList("my-replicated-topic"));
        System.out.println("Subscribe to topic " + "my-replicated-topic");
        int i = 0;
        while (true) {
            ConsumerRecords<String, String> records = consumer.poll(100);
            for (ConsumerRecord<String, String> record : records)
                System.out.printf("offset=%d,key=%s,value=%s\n", record.offset(), record.key(), record.value());
        }
    }
}
